#ifndef __MP_MQTT_CLIENT_SUBSCRIBE_H__
#define __MP_MQTT_CLIENT_SUBSCRIBE_H__

#include <string>
#include <map>
#include <vector>
#include <functional>

#include "logger.h"

namespace Gazella {
//topic, qos, payload
typedef std::function<void(const std::string&, uint8_t, const std::string&)> mqtt_subscribe_callback_t;

struct MqttClientSubscribeInfo {
    int qos;

    std::string topic_filter;
    uint16_t packet_id;

    bool wildcard = false;
    std::vector<std::string> topic_filter_parse;

    mqtt_subscribe_callback_t subscribe_callback;
};

class MqttClientSubscribe {
public:
    MqttClientSubscribe();
    ~MqttClientSubscribe();

    void add_subscribe(std::string topic_filter, uint8_t qos, uint16_t packet_id, mqtt_subscribe_callback_t subscribe_callback);
    void del_subscribe(std::string topic_filter);
    void del_subscribe(uint16_t packet_id);
    size_t match_topic_filter(std::string topic_name, uint8_t qos, std::vector<MqttClientSubscribeInfo>& subscribe_list);

private:
    //topic_filter: subscribe info
    std::map<std::string, MqttClientSubscribeInfo> m_subscribe_map;

    Logger *m_logger;
};
}

#endif